package com.part2.business.function.Impl;

import java.util.List;

import com.part2.action.common.validator.Validator;
import com.part2.beans.News;
import com.part2.common.query.Page;
import com.part2.dao.common.BaseDao;
import com.part2.dao.function.NewsDao;

public class NewsServiceImpl implements com.part2.business.function.NewsService {
	
	private BaseDao<News,String> baseDao;
	private NewsDao newsDao;

	public void setBaseDao(BaseDao<News, String> baseDao) {
		this.baseDao = baseDao;
	}

	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}

	public void addNews(News news) {
		// TODO Auto-generated method stub
		baseDao.save(news);
	}

	public void deleteNews(String id) {
		// TODO Auto-generated method stub
		if(Validator.isNotNull(id)){
			News ne = this.findNewsByPrimeKey(id);
			if(ne!=null)
				baseDao.delete(ne);
		}
	}

	public List<News> findNews() {
		// TODO Auto-generated method stub
		return baseDao.findAll(News.class);
	}

	public Page<News> findNews(Page<News> page,String type) {
		// TODO Auto-generated method stub
		return newsDao.findNews(page,type);
	}

	public News findNewsByPrimeKey(String id) {
		// TODO Auto-generated method stub
		return newsDao.findNewsByPrimeKey(id);
	}

	public void updateNews(News news) {
		// TODO Auto-generated method stub

	}

	public Page<News> findNewsBySearch(Page<News> page, String key) {
		// TODO Auto-generated method stub
		return newsDao.findNewsBySearch(page, key);
	}

	public List<News> findNewsByType(Short type) {
		// TODO Auto-generated method stub
		return newsDao.findNewsByType(type);
	}

}
